import React, { Component } from 'react';
import { FormControl, Button, Radio } from 'tinper-bee';
import { addWorkFileList, getManagerList, workFileSearchAddGroupListNew } from './workarchives.config.js';
import './ManagerModalContent.less';
import moment from 'moment';
moment.locale('zh-cn');
import Table from "bee-table";
import 'bee-table/build/Table.css';
export default class ManagerModalContent extends Component {
	constructor(props) {
		super(props);
		this.state = {
			data: [],
			text: '',
			selectedRow: [],
			pageNum: 1,
			isUseNewTeam: this.props.isUseNewTeam
		}
	}
	componentDidMount() {
		this.handlerGetSearchManager()
	}
	getColumns = () => {
		let _me = this;
		let  selectOptions = {
			10 : {value:10,label:"业主方",display: '业主方'},
			20:{ value:20,label:"施工方",display: '施工方'},
			30:{ value:30,label:"监理方",display: '监理方'},
			40:{ value:40,label:"设计方",display: '设计方'},
			50:{value:50,label:"客户方",display: '客户方'}
		};
		let coloumns = [
			{ title: "姓名", dataIndex: "userName", key: "userName", width: "20%" },
			{ title: "电话", dataIndex: "userMobile", key: "userMobile", width: "20%" },
			{ title: "邮箱", dataIndex: "userEmail", key: "userEmail", width: "20%"  },
			{ title: "企业", dataIndex: "defaultEntName", key: "defaultEntName", width: "40%"  },
			
		]
		if(this.state.isUseNewTeam){
			coloumns.push({ title: "企业角色", dataIndex: "defaultRole", key: "defaultRole", width: '40%', render:(text, record, idnex)=>{
				return(
					<span>{selectOptions[text]? selectOptions[text].label:'业主方'}</span> 
				)
			} })
		}
		return coloumns
	}
	onRowClick = (record, index, event) => {
		let saveManagerRecord = this.props.saveManagerRecord;
		let selectedRow = new Array(this.state.data.length);
		selectedRow[index] = true;
		this.setState({
			selectedRow: selectedRow
		});
		if (saveManagerRecord) {
			saveManagerRecord(record)
		}
	}
	handlerSaveManagerText = (e) => {
		let value = e.target.value;
		this.setState({
			text: value
		});
	}
	handlerGetSearchManager = (initNumFlag) => {
		if (initNumFlag) {
			this.setState({
				pageNum: 1,
				data: []
			}, () => {
				this.handlerGetDataList();
			});
		} else {
			this.handlerGetDataList();
		}

	}
	handlerGetDataList = () => {
		let param = {
			keyword: this.state.text,
			pageSize: 200,
			pageNum: this.state.pageNum
		};
		getManagerList(param,
			res => {
				let data = res.data.result;
				data.content.forEach((item, idnex) => {
					item['key'] = item['defaultEntId'] + item['userId'];
				})
				this.setState({
					data: [...this.state.data, ...data.content]
				}, () => {
					this.setState({
						selectedRow: new Array(this.state.data.length)
					});
				});
			},
			error => { }
		)
	}
	rowClassNameHandler = (record, index, indent) => {
		if (this.state.selectedRow[index]) {
			return 'selected';
		} else {
			return '';
		}
	}
	handlerSearchMoreManager = () => {
		let pageNum = this.state.pageNum;
		++pageNum;
		this.setState({
			pageNum: pageNum
		}, () => {
			this.handlerGetSearchManager(false);
		});
	}
	render() {
		return (
			<div className="manager--list">
				<div className="list--header clearfix">
					<div className="search-group clearfix">
						<FormControl size="lg" placeholder={`请输入姓名、电话、邮箱`} onChange={this.handlerSaveManagerText} />
						<a href="javascript:;" className="search-btn" onClick={() => this.handlerGetSearchManager(true)}></a>
					</div>
				</div>
				<div className="list--content">
					<Table data={this.state.data}
						columns={this.getColumns()}
						onRowClick={this.onRowClick}
						rowClassName={this.rowClassNameHandler}
						scroll={{ y: 300 ,x:"110%"}}/>
					<div><a className="search-more" onClick={this.handlerSearchMoreManager}>查看更多数据</a></div>
				</div>
			</div>
		)
	}
}